// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
  traceUser: true,
})

// 云函数入口函数
exports.main = async (event, context) => {
  const { OPENID } = cloud.getWXContext()
  const result = await cloud.openapi.subscribeMessage.send({
    touser: OPENID,
    page: `/pages/blog-comment/blog-comment?blogid=${event.blogId}`,
    data: {
      name1: {
        value: event.nickName
      },
      thing2: {
        value: event.fatherContent
      },
      thing3: {
        value: event.content
      },
      date4: {
        value: event.createTime
      }
    },
    templateId: 'JkrMpvhIrmfRU3BdLeWlzuGka-9BMJn-_6v52-94vY4',
    formId: event.formId
  })
  return result
}